package com.gxa.controller.xxh.FinancialManagement;

import com.gxa.common.R;
import com.gxa.entity.SysAccount;
import com.gxa.service.AccountManagementService;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@Api(value = "账号管理功能",tags = "账号管理功能API")
@RequiresRoles(value = {"超级管理员","院长","主任"},logical = Logical.OR)
@RequestMapping(value = "/FinancialManagement/Account")
public class AccountManagementController {

    @Autowired
    AccountManagementService accountManagementService;
    /**
     * 查询所有账户
     * @param currentPage
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/findAccountList",method = RequestMethod.GET)
    @ApiOperation(value = "展示所有账户接口",notes = "展示所有账户",httpMethod = "GET",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码数默认第一页",paramType = "query",dataType = "String"),
            @ApiImplicitParam(name = "pageSize",value = "每页显示记录数",paramType = "query",dataType = "String")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R findAccountList(Integer currentPage,Integer pageSize){
        return accountManagementService.findAccountList(currentPage,pageSize);
    }

    /**
     * 新增账户
     * @param sysAccount
     * @return
     */
    @RequestMapping(value = "/addAccount",method = RequestMethod.POST)
    @ApiOperation(value = "新增账户接口",notes = "新增账户",httpMethod = "POST",response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R addAccount(@RequestBody @ApiParam(name = "sysAccount",value = "账户实体",required = true) SysAccount sysAccount){
        return accountManagementService.addAccount(sysAccount);
    }

    /**
     * 根据姓名查询账号信息
     * @param name
     * @param currentPage
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/findAccountByName",method = RequestMethod.GET)
    @ApiOperation(value = "根据姓名查询账号信息接口",notes = "根据姓名查询账号信息",httpMethod = "GET",response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R findAccountByName(@RequestParam("name") String name,Integer currentPage,Integer pageSize){

        return accountManagementService.findAccountByName(name,currentPage,pageSize);
    }

    /**
     * 修改账户
     * @param sysAccount
     * @return
     */
    @RequestMapping(value = "/updateAccount",method = RequestMethod.POST)
    @ApiOperation(value = "修改账户接口",notes = "修改账户",httpMethod = "POST",response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R updateAccount(@RequestBody @ApiParam(name = "sysAccount",value = "账户实体",required = true) SysAccount sysAccount){

        return accountManagementService.updateAccount(sysAccount);
    }

    /**
     * 删除账户
     * @param id
     * @return
     */
    @RequestMapping(value = "/deleteAccount",method = RequestMethod.POST)
    @ApiOperation(value = "删除账户接口",notes = "删除账户",httpMethod = "POST",response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R deleteAccount(@RequestParam("id") Integer id){
        return accountManagementService.deleteAccount(id);
    }
}

